﻿using System;
using System.Collections.Generic;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using WPFEntityValidation.Entities;
using Entity.Validation.Core;
namespace WPFEntityValidation.ViewModels
{
    public class MainWindowViewModel : ViewModelBase
    {
        #region Fileds
        private Person _person;
        private RelayCommand _errorCommand;
        private IList<string> _errorList;

        #endregion

        #region Properties
        public Person Person
        {
            get { return _person ?? (_person = new Person()); }
            set
            {
                _person = value;
                this.RaisePropertyChanged(() => this.Person);
            }
        }

        public IList<String> ErrorList
        {
            get { return _errorList; }
            set
            {
                _errorList = value;
                this.RaisePropertyChanged(() => this.ErrorList);
            }
        }

        #endregion

        #region Commands

        public RelayCommand ErrorCommand
        {
            get { return _errorCommand ?? (_errorCommand = new RelayCommand(ExecuteErrorsCommand)); }
        }
        #endregion

        #region Command Methods
        private void ExecuteErrorsCommand()
        {
            if (this.Person.NotNull())
                this.ErrorList = this.Person.ValidateEntities();
        }
        #endregion
    }
}